package com.csp.mingyue.mybatis.service;

import com.csp.mingyue.mybatis.mapper.SysUserMapper;
import com.csp.mingyue.mybatis.model.MingYueUser;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * 用户缓存增删改查 （推荐）
 * @author Strive */
@Service
@RequiredArgsConstructor
public class MingYueUserNewService {

  private final SysUserMapper sysUserMapper;

  /**
   * 根据用户ID查询用户信息
   *
   * @param userId 用户ID
   * @return 用户信息
   */
  @Cacheable(cacheNames = "mybatis_cache_userInfo",key = "#userId")
  public MingYueUser queryUserById(Long userId) {
    return sysUserMapper.queryUserById(userId);
  }

  /**
   * 添加用户信息
   */
  public boolean addUser(MingYueUser user) {
    return sysUserMapper.addUser(user);
  }

  /**
   * 修改用户信息
   */
  @CacheEvict(cacheNames = "mybatis_cache_userInfo", key = "#userId")
  public boolean updateUser(MingYueUser user) {
    return sysUserMapper.updateUser(user);
  }

  /**
   * 删除用户信息
   * @param userId 用户ID
   */
  @CacheEvict(cacheNames = "mybatis_cache_userInfo", key = "#userId")
  public boolean delUser(Long userId) {
    return sysUserMapper.delUser(userId);
  }

}
